package com.xuan.chatroom.service;


import com.xuan.chatroom.mapper.MessageMapper;
import com.xuan.chatroom.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.List;

@Service
public class MessageService {
    @Autowired
    private MessageMapper messageMapper;

    public List<Message> getHistoryMessageBySessionId(Integer sessionId) {
        List<Message> messageList = messageMapper.getAllHistoryMessage(sessionId);
        Collections.reverse(messageList);
        return messageList;
    }

    public void insertMessage(Message message) {
        messageMapper.insertMessage(message);
    }
}
